package com.project.util.codingUtils;

import java.util.Random;

/**
 * Created by 卢泓佚  414814103@qq.com on 2021/9/27
 */
public class RandomStringGenerator {
    /**
     * 得到固定长度的随机字符串
     *
     * @param length 长度
     * @return 结果
     */
    public static String getRandomStringByLength(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int num = random.nextInt(base.length());
            sb.append(base.charAt(num));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(getRandomStringByLength(32));
    }
}
